package com.gugee.ins.data.blogger.es.core;

import com.gugee.ins.common.dal.service.statistics.InsStBloggerRealFollowingDao;
import com.gugee.ins.common.model.es.blogger.InsBlogger;
import com.gugee.ins.common.model.mysql.blogger.InsBloggerMain;
import com.gugee.ins.common.model.mysql.statistics.InsStBloggerRealFollowing;
import com.gugee.ins.data.blogger.es.config.InsBloggerEsMapping;
import com.xiguaji.boot.toolkit.elasticsearch.RestClientHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 大播主广告信息更新到ES
 */
@Service
public class BloggerMediaAdToEsService extends EsBaseService{

    @Autowired
    InsBloggerEsMapping insBloggerEsMapping;

    @Autowired
    InsStBloggerRealFollowingDao insStBloggerRealFollowingDao;

    @Override
    protected InsBlogger structureEsBlogger(InsBloggerMain insBloggerMain) {
        InsBlogger insBloggerEs = insBloggerEsMapping.mapper(insBloggerMain);
        InsStBloggerRealFollowing insStBloggerRealFollowing = insStBloggerRealFollowingDao.findByUid(insBloggerEs.getUid());
        insBloggerEs.setAdCount(insStBloggerRealFollowing.getAdCount());
        insBloggerEs.setAdTec(insStBloggerRealFollowing.getAdTec());
        return insBloggerEs;
    }

    @Override
    protected void toEsHandler(String esIndex, List<InsBlogger> insBloggers) {
        RestClientHelper.upsert(esIndex,insBloggers);
    }
}
